package service.center.message;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Component
public class 阿里云短信 {

    private static String AccessKey;
    private static  String Secret;

    @Value("${aliyun.AccessKey}")
    public void setAccessKey(String AccessKey1) {
        AccessKey=AccessKey1;
    }

    @Value("${aliyun.AccessKey.Secret}")
    public void setSecret(String Secret1) {
        Secret=Secret1;
    }

    //天气提醒专用方法
    public static String 天气提醒(String 手机号码,String 提醒内容){

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", AccessKey, Secret);
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", 手机号码);
        request.putQueryParameter("SignName", "saber");
        request.putQueryParameter("TemplateCode", "SMS_204751754");
        request.putQueryParameter("TemplateParam", 提醒内容);
        try {
            CommonResponse response = client.getCommonResponse(request);

            return  response.toString();
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return  "ok";
    }    //天气提醒专用方法


}
